﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Empires.Infrastructure.Entities.Repository;
using Empires.Infrastructure.Entities.Entity;

namespace Empires.Infrastructure.Entities.EntityCache
{
    public class CorporationCache : EntitiesCache<Corporation>
    {
        protected override bool ValidateParameter(params string[] keys)
        {
            return keys.Length == 1 && !String.IsNullOrEmpty(keys[0]);
        }

        protected override Corporation LoadDataItem(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                string username = keys[0];
                var corp = new Corporation().Find(c => c.Master == username);
                return corp;
            }
            return null;
        }

        protected override string BuildKey(params string[] keys)
        {
            if (ValidateParameter(keys))
            {
                return String.Format("GetCorporationEntity_{0}", keys[0]);
            }
            return string.Empty;
        }

        protected override string BuildKey(Corporation data)
        {
            if (data != null && !String.IsNullOrEmpty(data.Master))
            {
                return BuildKey(data.Master);
            }
            return string.Empty;
        }
    }
}
